<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8" %>
<%@include file="/jsp/common/head.jsp" %>

<div class="right">
	<div class="location">
		<strong>你现在所在的位置是:</strong>
		<span>订单管理页面</span>
	</div>
	<div class="search">
		<form method="get" action="${pageContext.request.contextPath }/bill/list">
			<input name="pageNo" value="1" class="input-text" type="hidden">
			<span>商品名称：</span>
			<input name="productname" type="text" value="${productname}">

			<span>供应商：</span>
			<select name="providerid" id="providerid">
				<option value="0">--请选择--</option>
			</select>

			<span>是否付款：</span>
			<select name="ispayment">
				<option value="0">--请选择--</option>
				<option value="1" ${ispayment == 1 ? "selected=\"selected\"":"" }>未付款</option>
				<option value="2" ${ispayment == 2 ? "selected=\"selected\"":"" }>已付款</option>
			</select>

			<input value="查 询" type="submit" id="searchbutton">
			<a href="${pageContext.request.contextPath }/jsp/billadd.jsp">添加订单</a>
		</form>
	</div>
	<!--账单表格 样式和供应商公用-->
	<table class="providerTable" cellpadding="0" cellspacing="0">
		<tr class="firstTr">
			<th width="10%">图书编码</th>
			<th width="20%">图书名称</th>
			<th width="10%">图书摘要</th>
			<th width="10%">上传人</th>
			<th width="10%">上传时间</th>
			<th width="30%">操作</th>
		</tr>
		<c:forEach var="bill" items="${pageInfo.list }" varStatus="status">
			<tr>
				<td>
					<span>${bill.categoryId }</span>
				</td>
				<td>
					<span>${bill.title }</span>
				</td>
				<td>
					<span>${bill.summary}</span>
				</td>
				<td>
					<span>${bill.uploaduser}</span>
				</td>

				<td>
					<span>
					<fmt:formatDate value="${bill.createdate}" pattern="yyyy-MM-dd"/>
					</span>
				</td>
				<td>
                    <span><a class="viewBill" href="${pageContext.request.contextPath }/bill/view?id=${bill.id}" billid=${bill.id } billcc=${bill.billcode }><img
							src="${pageContext.request.contextPath }/statics/images/read.png" alt="查看" title="查看"/></a></span>
					<span><a class="modifyBill" href="${pageContext.request.contextPath }/bill/toUpdate?id=${bill.id}" billid=${bill.id } billcc=${bill.billcode }><img
							src="${pageContext.request.contextPath }/statics/images/xiugai.png" alt="修改"
							title="修改"/></a></span>
					<span><a class="deleteBill" href="javascript:del(${bill.id});" billid=${bill.id } billcc=${bill.billcode }><img
							src="${pageContext.request.contextPath }/statics/images/schu.png" alt="删除" title="删除"/></a></span>
				</td>
			</tr>
		</c:forEach>
	</table>
	<div class="page-bar">
		<ul class="page-num-ul clearfix">
			<li>共${pageInfo.total }条记录&nbsp;&nbsp; ${pageInfo.pageNum }/${pageInfo.pages }页</li>
			<c:if test="${pageInfo.pageNum > 1}">
				<a href="javascript:page_nav(document.forms[0],1);">首页</a>
				<a href="javascript:page_nav(document.forms[0],${pageInfo.pageNum-1});">上一页</a>
			</c:if>
			<c:if test="${pageInfo.pageNum < pageInfo.pages }">
				<a href="javascript:page_nav(document.forms[0],${pageInfo.pageNum+1 });">下一页</a>
				<a href="javascript:page_nav(document.forms[0],${pageInfo.pages });">最后一页</a>
			</c:if>
			&nbsp;&nbsp;
		</ul>
		<span class="page-go-form"><label for="inputPage">跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" value="${pageInfo.pageNum}"/>页
	     <button type="button" class="page-btn"
				 onClick='jump_to(document.forms[0],document.getElementById("inputPage").value)'>GO</button>
		</span>
	</div>
</div>
</section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeBi">
	<div class="removerChid">
		<h2>提示</h2>
		<div class="removeMain">
			<p>你确定要删除该订单吗？</p>
			<a href="#" id="yes">确定</a>
			<a href="#" id="no">取消</a>
		</div>
	</div>
</div>

<%@include file="/jsp/common/foot.jsp" %>
<script>

    //当页面加载的时候，加载供应商的下拉列表框
    $.ajax({
        url:"/provider/list",
        success:function (data) {
            console.log(data);
            var options = "";
            //遍历数组中的信息，然后把信息添加到option标签中
            for(var i = 0 ; i < data.length ; i++){
                //data[i] 获取数组中的一个元素
                options += "<option value='"+data[i].id+"'>"+data[i].proname+"</option>";
            }

            //把option标签添加到
            $("#providerid").append(options);
            //做供应商的回显  这是一个表单
            $("#providerid").val(${providerid});//相当于默认选中这个value的下拉项
        }
    })

    /**
     *删除订单的页面方法?
     *  1.提示用户正在删除
     *  2.当用户确定删除的时候，我把用户的请求提交到到后台
     * @param id 用户要删除数据的主键
     */
    function del(id) {
        if(confirm('您确定要删除吗?')){
            //如果确定要删除,那就跳转到后台去
            location.href = "/bill/delete?id="+id;
        }
    }


    /**
     * 分页的方法
     * @param form 要提交的表单对象
     * @param pageNo 当前用户选择的分页信息
     */
    function page_nav(form,pageNo) {
        //把最新的页码值赋值到表单中隐藏域pageNo上面
        form.pageNo.value = pageNo;

        //提交表单
        form.submit();
    }

    function jump_to(form,pageNo) {
        //需要判断用户输入的页码信息是否有问题
        /*if(pageNo < 1 || pageNo > ${pageInfo.pages}){
            alert("输入不合法");
            return; //方法结束，后面的就不执行了
        }*/
        if (pageNo < 1){
            pageNo = 1;
        }
        if (pageNo > ${pageInfo.pages}) {
            pageNo = ${pageInfo.pages};
        }

        //如果合法
        page_nav(form,pageNo); //发送用户请求
    }
</script>
